package com.jcx.ldzj.controller;

import com.baomidou.mybatisplus.extension.api.R;
import com.jcx.ldzj.emun.MyCode;
import org.apache.shiro.ShiroException;
import org.apache.shiro.authc.LockedAccountException;
import org.apache.shiro.authz.AuthorizationException;
import org.apache.shiro.authz.UnauthenticatedException;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@ControllerAdvice
public class NoPermissionException {
    @ExceptionHandler({LockedAccountException.class})
    @ResponseBody
    public R<String> lockedAccountExceptionHandler(HttpServletRequest request, Exception exception) throws Exception {
        return R.failed(MyCode.账号被锁定_请半小时后再试);
    }
    @ExceptionHandler({UnauthorizedException.class , AuthorizationException.class , ShiroException.class})
    @ResponseBody
    public R<String> unauthorizedHandler(HttpServletRequest request, Exception exception) throws Exception {
        return R.failed(MyCode.该接口未授权_请联系管理员);
    }


    @ExceptionHandler({UnauthenticatedException.class})
    @ResponseBody
    public R unauthenticatedHandler(HttpServletRequest request, Exception exception) throws Exception {
        return R.failed(MyCode.该接口未授权_请联系管理员);
    }
}
